<?php
namespace app\console\controller;
use app\model\Construction as SelfModel;
use app\model\Member;
use app\model\Profession;

use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Request;
use think\facade\Route;
use think\facade\View;
use think\facade\Db;
use think\facade\Cache;
use think\facade\Cookie;
class Construction extends Base
{



    public function initialize()
    {
        parent::initialize();
        $this->model = "\app\model\Construction";
        $this->list_rows = 100;
        
    }

    public function select()
    {
        $member = Member::where([['status', '=', 1]])->order(['sort' => 'asc', 'id' => 'desc'])->select()->toArray();
        View::assign('member', $member);

        $profession = Profession::where([['status', '=', 1]])->where([['parent_id','<>',0]])->order(['sort' => 'asc', 'id' => 'desc'])->select()->toArray();
        View::assign('profession', $profession);
        $profession2 = Profession::where([['status', '=', 1]])->where('parent_id',input('cat_id'))->order(['sort' => 'asc', 'id' => 'desc'])->select()->toArray();
        View::assign('profession2', $profession2);

    }
    public function index()
    {

        $param = Request::param();

        $data = $this->model::withSearch(array_keys($param),$param)->order($this->order)->paginate(['query' => $param,'list_rows'=>$this->list_rows])->each(function ($item,$key){

        });

        $this->select();
        return View::fetch('', ['data' => $data]);
    }


    public function fenxiao()
    {
        $lev = 0;//当前的级别
        $member_id = 0;//当前的会员ID
        $p_count = 0;//平级次数
        $k_count = 0;//跨级次数
        $money = 100;
        $data = [];
        foreach ($data as $k => $v) {
            if ($k == 0) {
                //每日发放
            }
            if ($k == 1) {
                //直推发放
            }
            if ($lev == 0 && $v['lev'] > $lev) { //第一次进来自己和自己不能吃管理加速等等
                $lev = $v['lev'];
                $member_id = 4;
                if ($k == 0) {
                    continue;
                } else {
                    //管理奖;
                    continue;
                }
            }
            //程序有可能一直 0
            if ($lev > 0) { //正式玩平级 管理和跨级奖励

                if($v['lev'] > $lev){
                    $lev = $v['lev'];
                    $p_count = $k_count = 0;
                    $args = $v['member_id']*($lev['lev']-$lev)*$money;
                }
                if($v['lev'] == $lev){ //平级
                    $p_count++;
                }
                if($v['lev'] < $lev){ //跨级
                    $k_count++;
                }
                if($p_count == 1){

                }
                if($k_count == 1){

                }

            }

        }
    }





}